<template>
  <!-- 选择项目业态 -->
  <a-select placeholder="选择项目业态" v-bind="$attrs" v-on="$listeners" v-model="currentValue" allowClear>
    <a-spin v-if="fetching" slot="notFoundContent" size="small" />
    <a-select-option v-for="i in formats" :key="i.id" :value="i.id">{{ i.name }}</a-select-option>
  </a-select>
</template>
<script>
  import { getProjectFrom } from '@/api/project/projects'

export default {
  inheritAttrs: false,
  props: {
    // v-model绑定的数据
    value: {
      type: [Array, String],
    },
  },
  methods:{
    getProjectFormat(){
      this.fetching = true
       getProjectFrom().then(res=>{
         this.fetching = false
         this.formats = res.data
       }).catch(()=>{
         this.fetching = false
       })
    }
  },
  mounted() {
    this.getProjectFormat()
  },
  data() {
    return {
      fetching: false,
      formats: [],
    }
  },
  computed: {
    // 转换绑定的选中数据，与v-model同步
    currentValue: {
      get: function () {
        return this.value
      },
      set: function (value) {
        this.$emit('input', value)
      },
    },
  },
}
</script>
